package bb.lanxing;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.baidu.mapapi.model.LatLng;
import com.github.mikephil.charting.utils.Utils;

import android.content.Context;
import android.content.Intent;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;

import bb.lanxing.test.SimpleViewActivity;
import bb.lanxing.util.map.MapConfigs;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class JavaAndroidTest {
    private static final int FACTOR = 10_000_000;

    @BeforeClass
    public static void beforeClass() {
        System.out.println("beforeClass");
    }

    @AfterClass
    public static void afterClass() {
        System.out.println("afterClass");
    }

    @Test
    public void useAppContext() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        assertEquals("bb.lanxing", appContext.getPackageName());
        Intent intent = new Intent(appContext, SimpleViewActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        // appContext.startActivity(intent);
        ActivityTestRule<SimpleViewActivity> activityTestRule =
                new ActivityTestRule<>(SimpleViewActivity.class, false, false);
        activityTestRule.launchActivity(intent);
    }

    @After
    public void after() {
        System.out.println("after");
    }

    @Before
    public void before() {
        System.out.println("before");
    }

    @Test
    public void locationTest() {
        LatLng latLng = MapConfigs.getNotNullLastLocation();
        System.out.println("locationTest latLng  = " + latLng);
        double test = Double.parseDouble("39.90280765527851");
        System.out.println("locationTest test  = " + test);
    }

    @Test
    public void baseTest() {
        double test = Utils.DOUBLE_EPSILON;
        // baseTest test = 4.9E-324
        System.out.println("baseTest test = " + test);
        if (test == Utils.DOUBLE_EPSILON) {
            System.out.println("baseTest == ");
        }
        String str = String.valueOf(test);
        double test1 = Double.parseDouble(str);
        System.out.println("baseTest test1 = " + test1);

        int num1 = (int) (116.4701287 * FACTOR);
        System.out.println("num1 = " + num1);
    }
}
